package com.lzx.iteam.net;

import android.os.Message;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.util.StringUtil;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 05月 04日
 * Time: 下午2:06
 *
 * @QQ : 1234567890
 * **********************************
 */
public class RemoveMemberMsg extends CcMsgStructure {
    private static final String TAG = "RemoveMemberMsg";
    private Message mmCallback;

    public RemoveMemberMsg(Message mmCallback) {
        this.mmCallback = mmCallback;
    }

    @Override
    public void onReceive(JSONObject data) {
        int backResult = 0;
        try {
            JSONObject jsonObject = data.getJSONObject(AsynHttpClient.KEY_CC_DATA);
            backResult = jsonObject.getInt("ok");

        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (mmCallback != null) {
            mmCallback.obj = backResult;
            mmCallback.arg1 = 0;
            mmCallback.sendToTarget();
            return;
        }
    }

    @Override
    public void onError(int error, Object ret) {
        if (mmCallback != null) {
            mmCallback.arg1 = -1;
            mmCallback.obj = ret;
            mmCallback.sendToTarget();
        }
        String errorMsg = null;
        if (ret != null) {
            JSONObject jData = null;
            try {
                jData = new JSONObject(ret.toString());
                errorMsg = jData.getString("msg");
            } catch (JSONException e) {
                errorMsg = "服务端数据解析失败!";
                e.printStackTrace();
            }

        }
        if(mmCallback != null){
            mmCallback.arg1 = error;
            if(!StringUtil.isEmpty(errorMsg)){
                mmCallback.obj = errorMsg;
            }else{
                mmCallback.obj = Constants.NETWORK_WRROR;
            }
            mmCallback.sendToTarget();
        }
    }
}
